<template>
	<view class="library">
		<view class="title">{{arr.title}}</view>
		<view class="msg">
			<view><image src="@/static/time.png" mode="widthFix"></image>{{arr.createtime}}</view>
			<text>阅读量:{{arr.read}}</text>
		</view>
		<view class="content" v-html="arr.content"></view>
		<view class="link" @click="copy" v-if="arr.link">
			项目资源
		</view>
	</view>
</template>

<script>
	var _this
	export default {
		data() {
			return {
				arr:{}
			};
		},
		onLoad(option) {
			_this = this
			_this.getLibrary(option.id)
		},
		methods:{
			getLibrary:async function(id){
				await _this.$api.getLibrary({'id':id},res=>{
					_this.arr = res.data[0]
					_this.arr.createtime = _this.$util.timeToDate(_this.arr.createtime)
					const regex = new RegExp('<img', 'gi');
					_this.arr.content = _this.arr.content.replace(regex, `<img style="width: 100%;"`);
					const regex2 = new RegExp('<span', 'gi');
					_this.arr.content = _this.arr.content.replace(regex2, `<span style="line-height:1.5"`);
				})
			},
			copy(){
				uni.setClipboardData({
					data: _this.arr.link,
					success: function () {
						uni.showToast({
							icon:'success',
							title: '复制成功~~',
							duration: 2000
						});
					},
					fail: function () {
						uni.showToast({
							icon:'error',
							title: '出错了~~',
							duration: 2000
						});
					},
				});
			}
		}
	}
</script>

<style lang="scss">
	.library{
		padding: 24rpx 24rpx 48rpx 24rpx;
		box-sizing: border-box;
		.title{
			text-align: center;
			font-size: 36rpx;
			font-weight: bold;
			margin-bottom: 24rpx;
		}
		.msg{
			display: flex;
			justify-content: space-between;
			font-size: 24rpx;
			color: #9B9B9B;
			margin-bottom: 24rpx;
			view{
				display: flex;
				align-items: center;
				gap: 0 12rpx;
			}
			image{
				width: 32rpx;
			}
		}
		.content{
			margin-bottom: 24rpx;
			img{
				width: 100%;
				display: block;
			}
		}
		.link{
			width: 100%;
			height: 86rpx;
			color: #fff;
			background-color: #1373FF;
			border-radius: 32rpx;
			font-size: 36rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
</style>
